package com.example.authfeign.service;

import com.example.authfeign.mapper.SPrivilegeUserMapper;
import com.example.util.model.PrivilegeUser;
import com.example.util.model.Role;
import com.example.util.model.SecurityLogin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Configuration // 定义配置类
@Service   // 定义服务类
@RestController  // @RestController注解相当于@Controller + @ResponseBody 合在一起的作用。
@RequestMapping("/api/v1") //定义路径中间层
public class PrivilegeUserService {
    private final Logger logger= LoggerFactory.getLogger(PrivilegeUserService.class);
	@Autowired
	private SPrivilegeUserMapper sPrivilegeUserMapper;
	
//	@Cacheable(value="privilegeUser", key="'loginName'")
    @GetMapping("/privilegeUser/{loginName}")  //使用  GetMapping 相当于 RequestMapping + method.GET  里面的路径规则可学习RESTful API
      PrivilegeUser privilegeUser(@PathVariable(value = "loginName") String loginName) {
        logger.info("开始查询.....");
        try {
            Thread.sleep(3 * 1000l);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        PrivilegeUser privilegeUser=sPrivilegeUserMapper.getCurrentUserByloginName(loginName);
        logger.info(privilegeUser.toString());
        logger.info("查询结束......");

        return privilegeUser;
    }
    @GetMapping("/userInfoByLoginName/{loginName}")
   SecurityLogin userInfoByLoginName(@PathVariable(value = "loginName") String loginName){
        return  sPrivilegeUserMapper.findUserInfsByLoginName(loginName) ;
    }
    @GetMapping("/userRoles/{id}")
    List<Role> userRoles(@PathVariable(value = "id") Long id){
//        return sPrivilegeUserMapper.getRolesByUserId(id);
        return  sPrivilegeUserMapper.getRolesByUserId(id) ;
    }
}
